﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMS_MAV.DTO.FinanceType;
using WMS_MAV.DTO.Payable;
using WMS_MAV.DTO.Receivable;

namespace WMS_MAV.Controllers
{
    public class PayableController : Controller
    {
        private readonly IConfiguration _configuration;
        public PayableController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 应付显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult PayableShow()
        {
            return View();
        }
        /// <summary>
        /// 返回应付数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetPayableShow(PayableShowDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchaseRead/api/Payable/GetPayableList?PageIndex=" + dto.PageIndex + "&pageSize=" + dto.PageSize + "&payableSerialNumber=" + dto.PayableSerialNumber + "&payableName=" + dto.PayableName + "&financeTypeName=" + dto.FinanceTypeName + "&payee=" + dto.Payee + "&startTime=" + dto.StartTime + "&endTime=" + dto.EndTime + "&status=" + dto.Status;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 添加应付信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetPayableAdd(PayableAddDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Payable/GetPayableAdd";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 删除应付信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetPayableDel(PayableDelDto dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Payable/GetPayableDelete";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 批量删除应付信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetPayableDelRange(PayableRangeDelDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Payable/GetPayableDeleteRange";
            var list = "{\"ids\":" + dto.Ids + "}";
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 查看应收详情
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetPayableModel(PayableModelDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchaseRead/api/Payable/GetPayableModel?PayableId=" + dto.PayableId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 修改应收信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetPayableUpd(PayableUpdDto obj1, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Payable/GetPayableUpdate";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 审批应付信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetPayableAudit(PayableAuditDto obj1, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Payable/GetPayableAudit";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 添加实付信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetActuallypaidAdd(ActuallypaidAddDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Payable/GetActuallpaidAdd";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
    }
}
